package pl.put.to.regression.verification;

import java.util.List;

import pl.put.to.regression.data.DataInstance;
import pl.put.to.regression.data.DataSet;

public abstract class AErrorVeryficator implements IErrorVeryficator {

	@Override
	public double countError(DataSet data, List<Double> coefficients) {
		double error = 0;

		for (DataInstance instance : data.getInstances()) {
			double yCounted = 0;

			for (int i = 0; i < data.getNumberOfVariables(); ++i) {
				yCounted += (instance.getVariableValues().get(i) * coefficients.get(i));
			}

			double yReal = instance.getClassVariableValue();

			error = modifyError(error, yReal, yCounted);
		}

		error = normalizeError(error, data.getNumberOfInstances());
		return error;
	}

	protected abstract double modifyError(double currentError, double yReal, double yCounted);

	protected abstract double normalizeError(double error, int dataSize);

}
